﻿using BCCommon;
using BCDto.CRM.BigCustomer;
using BCService.CRM.BigCustomer;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.CRM.BigCustomer
{
    /// <summary>
    /// 大客户
    /// </summary>
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BigCustomerController : ManagementBaseController
    {
        #region var
        private IBigCustomerService bigCustomerService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public BigCustomerController(IBigCustomerService bigCustomerService)
        {
            this.bigCustomerService = bigCustomerService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新大客户纪录
        /// </summary>
        /// <param name="dto">大客户数据模型</param>
        /// <returns></returns>
        [Log("添加新大客户纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(BigCustomerRequestDto), 200)]
        public IActionResult Post([FromBody] BigCustomerRequestDto dto)
        {
            var a = bigCustomerService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT   修改
        /// <summary>
        /// 修改大客户记录
        /// </summary>
        /// <param name="dto">大客户修改模型</param> 
        /// <returns></returns>
        [Log("修改大客户等级")]
        [HttpPut]
        [ProducesResponseType(typeof(BigCustomerDto), 200)]
        public IActionResult Put([FromBody] BigCustomerPutDto dto)
        { 
            return Ok(bigCustomerService.Update(dto, this.Admin));
        }
        #endregion 


        #region PUT   大客户信息启用禁用业务类型
        /// <summary>
        /// 启用禁用业务类型
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [Log("大客户信息启用禁用业务类型")] 
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(BigCustomerDto), 200)]
        public IActionResult EnableBusinessType([FromBody] BigCustomerEnableBusinessTypePutDto dto)
        {
            var a = Ok(bigCustomerService.UpdateEnableBusinessType(dto, this.Admin));
            return a;
        }
        #endregion

        #region 设置同城协议价格和最大重量
        /// <summary>
        /// 设置同城协议价格和最大重量
        /// </summary>
        /// <param name="bigCustomerId">大客户Id</param>
        /// <param name="sameCityPrice">同城协议价格</param>
        /// <param name="sameCityPriceMaxWeight">同城协议价格最大重量</param>
        /// <returns></returns>
        [Log("设置同城协议价格和最大重量")]
        [HttpPut("[action]/{big_customer_id}/{same_city_price}/{same_city_price_max_weigth}")]
        [ProducesResponseType(typeof(BigCustomerDto), 200)]
        public IActionResult SetSameCityPrice(
           [FromRoute(Name = "big_customer_id")] long bigCustomerId,
           [FromRoute(Name = "same_city_price")] decimal? sameCityPrice,
           [FromRoute(Name = "same_city_price_max_weigth")] decimal? sameCityPriceMaxWeight)
        {
            var a = Ok(bigCustomerService.SetAgreementPrice(bigCustomerId,sameCityPrice,null, sameCityPriceMaxWeight, null,null,null,this.Admin));
            return a;
        }
        #endregion

        #region 设置小件协议价格和最大重量
        /// <summary>
        /// 设置小件协议价格和最大重量
        /// </summary>
        /// <param name="bigCustomerId">大客户Id</param>
        /// <param name="smallPiecesPrice">小件协议价格</param>
        /// <param name="smallPiecesPriceMaxWeight">小件协议价格最大重量</param>
        /// <returns></returns>
        [Log("设置小件协议价格和最大重量")]
        [HttpPut("[action]/{big_customer_id}/{small_pieces_price}/{small_pieces_price_max_weigth}")]
        [ProducesResponseType(typeof(BigCustomerDto), 200)]
        public IActionResult SetSmallPiecesPrice(
            [FromRoute(Name = "big_customer_id")] long bigCustomerId,
            [FromRoute(Name = "small_pieces_price")] decimal? smallPiecesPrice,
            [FromRoute(Name = "small_pieces_price_max_weigth")] decimal? smallPiecesPriceMaxWeight)
        {
            var a = Ok(bigCustomerService.SetAgreementPrice(bigCustomerId, null, smallPiecesPrice, null, smallPiecesPriceMaxWeight,null,null, this.Admin));
            return a;
        }
        #endregion
        #region 设置跑腿协议价格和最大重量
        /// <summary>
        /// 设置跑腿协议价格和最大重量
        /// </summary>
        /// <param name="bigCustomerId">大客户Id</param>
        /// <param name="runErrandsPrice">跑腿协议价格</param>
        /// <param name="runErrandsPriceMaxWeight">跑腿协议价格最大重量</param>
        /// <returns></returns>
        [Log("设置跑腿协议价格和最大重量")]
        [HttpPut("[action]/{big_customer_id}/{run_errands_price}/{run_errands_price_max_weight}")]
        [ProducesResponseType(typeof(BigCustomerDto), 200)]
        public IActionResult SetRunErrandsPiecesPrice(
            [FromRoute(Name = "big_customer_id")] long bigCustomerId,
            [FromRoute(Name = "run_errands_price")] decimal? runErrandsPrice,
            [FromRoute(Name = "run_errands_price_max_weight")] decimal? runErrandsPriceMaxWeight)
        {
            var a = Ok(bigCustomerService.SetAgreementPrice(bigCustomerId, null, null, null, null, runErrandsPrice, runErrandsPriceMaxWeight, this.Admin));
            return a;
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除大客户纪录
        /// </summary>
        /// <param name="bigCustomerId">大客户ID</param>
        /// <returns></returns>
        [Log("删除大客户纪录")]
        [HttpDelete("{big_customer_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "big_customer_id")] long bigCustomerId)
        {
            bigCustomerService.Delete(bigCustomerId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条大客户纪录
        /// </summary>
        /// <param name="bigCustomerId">大客户ID</param>
        /// <returns></returns>
        [HttpGet("{big_customer_id}")]
        [ProducesResponseType(typeof(BigCustomerDto), 200)]
        public IActionResult Get([FromRoute(Name = "big_customer_id")] long bigCustomerId)
        {
            return (Ok(bigCustomerService.GetById(bigCustomerId)));

        }
        #endregion

        #region Query 查询大客户
        /// <summary>
        /// 查询大客户
        /// </summary>
        /// <param name="bigCustomerGroupId">大客户组Id</param>
        /// <param name="bigCustomerLevel">等级</param>
        /// <param name="provinceCode">省编码</param>
        /// <param name="cityCode">市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="customerName">客户名</param>
        /// <param name="phone">电话</param>
        /// <param name="weChatNo">微信号</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BigCustomerViewDto>), 200)]
        public IActionResult Query(
           [FromQuery(Name = "big_customer_group_id")] long? bigCustomerGroupId,
           [FromQuery(Name = "big_customer_level")] int? bigCustomerLevel,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "city_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "customer_name")] string customerName,
            [FromQuery(Name = "phone")] string phone,
            [FromQuery(Name = "we_chat_no")] string weChatNo,
           [FromQuery(Name = "start")] DateTime? start,
           [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "index")] int? pageIndex = 1, 
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(bigCustomerService.GetList(this.Admin,bigCustomerGroupId,bigCustomerLevel,customerName,provinceCode,cityCode,countyCode,phone,weChatNo,start,end,pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion
    }

}
